{% include "../public/min-header.html" %}
<style>.orderby{width:50px;}</style>
<body>
<div class="wrapper">
	<section class="content">
	<div class="row">
		<form action="" method="post" id="ctlform" name="ctlform">
			<table class="table table-bordered table-striped" id="toolbar">
				<tr>
					<th class="col-xs-2">模型标题:</th>
					<th class="col-xs-2">控制器</th>
					<th class="col-xs-2">Action</th>					
					<th class="col-xs-2">父级菜单:</th>
					<th class="col-xs-1">显示</th>
					<th class="orderby">排序</th>
					<th class="col-xs-2"><a href="javascript:void(0)" batch="add_new_line" onclick="add_new_line()">新增一行</a></th>
				</tr>
				{% for mod in modules %}
                    {%if mod%}
					<tr id="mod-ctl-{{mod.mod_id}}">
						<td><input type="text" name="module[{{mod.mod_id}}][title]" class="form-control" class="col-xs-3" value="{{mod.title}}"></td>
						<td><input type="text" name="module[{{mod.mod_id}}][ctl]" class="form-control" value="{{mod.ctl}}"></td>
						<td><input type="text" name="module[{{mod.mod_id}}][act]" class="form-control" value="{{mod.act}}"></td>
						<td>
							<select name="module[{{mod.mod_id}}][parent_id]" class="form-control">
								{% for v in menu_tree%}
                                    {% if v %}
									<optgroup label="{{v.title}}">
										{% for vv in v.menu%}
                                        {% if vv %}
											<option value="{{vv.mod_id}}"{% if vv.mod_id == mod.parent_id %} selected="selected"{% endif %}>{{vv.title}}</option>
                                        {% endif%}
										{% endfor %}
									</optgroup>
                                    {% endif%}
								{% endfor %}
							</select>
						</td>
						<td>
							<input type="radio" name="module[{{mod.mod_id}}][visible]" value="1" {% if mod.visible == 1 %}checked{% endif %}>是
							<input type="radio" name="module[{{mod.mod_id}}][visible]" value="0" {% if mod.visible == 0 %}checked{% endif %}>否
						</td>
						<td><input type="text" name="module[{{mod.mod_id}}][orderby]" class="form-control" value="{{mod.orderby}}"></td>
						<td><a href="javascript:void(0)" data-post-url="{{helper.pathFor('adcoset')}}" data-id="{{mod.mod_id}}" data-jump-url="{{helper.pathFor('adstcld',{mod_id:pid})}}"  data-type="module" class="setRemove">删除</a></td>
					</tr>
                {% endif %}
				{% endfor %}
			</table>
		</form>
	</div>
	<div class="pull-right">
		<input type="button" class="btn btn-primary" onclick="ctlsubmit()" value="提 交 数 据" />
	</div>
	</section>
	<select style="display:none;" id="mod_tree">
		{% for v in menu_tree %}
            {% if v%}
            <optgroup label="{{v.title}}">
			{% for vv in v.menu %}
                {% if vv%}
				<option value="{{vv.mod_id}}"{%if pid==vv.mod_id %}selected="selected"{% endif %}>{{vv.title}}</option>
                {% endif %}
			{% endfor %}
            </optgroup>
			{% endif %}
		{% endfor %}
	</select>
</div>
<script>
var kt = 0;

$(function(){
	//add_new_line();
});

function add_new_line(){
	var tmpstr = '';
	tmpstr += '<tr>';
	tmpstr += '<td class="col-xs-2"><input type="text" name="data['+kt+'][title]"  value=""></td>';
	tmpstr += '<td class="col-xs-2"><input type="text" name="data['+kt+'][ctl]"  value=""></td>';
	tmpstr += '<td class="col-xs-2"><input type="text" name="data['+kt+'][act]" value=""></td>';
	tmpstr += '<td class="col-xs-2">';
	tmpstr += '<select name="data['+kt+'][parent_id]">'
	tmpstr += $('#mod_tree').html();
	tmpstr += '</select></td>';
	tmpstr += '<td class="col-xs-1"><input type="radio" name="data['+kt+'][visible]" value="1">是<input type="radio" name="data['+kt+'][visible]" value="0">否</td>';
	tmpstr += '<td class="orderby"><input type="text" name="data['+kt+'][orderby]" value="50"></td>';
	tmpstr += '<td class="col-xs-2"><a href="###" batch="remove_item_line" onclick="remove_line(this)">取消</a></td>';
	tmpstr += '</tr>';
	$('#toolbar').append(tmpstr);
	kt++;
}

function remove_line(obj){
	$(obj).parent().parent().remove();
	kt--;
	return false;
}

function ctlsubmit(){
	var data = $('#ctlform').serializeArray();
	$.ajax({
		type:'post',
		dataType:'json',
		url:"{{helper.pathFor('adstcld')}}",
		data:data,
		success:function(res){
			console.log(res);
			if(res.status == 1){
				window.parent.call_back(1);	
			}else{
				window.parent.call_back(0);	
			}
		}
	});
}
</script>
{% include "../public/main-footer.html" %}